/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

package soft.hb.fragment;

import android.Manifest;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.mylhyl.acp.Acp;
import com.mylhyl.acp.AcpListener;
import com.mylhyl.acp.AcpOptions;

import java.util.List;

import soft.hb.R;
import soft.hb.activity.CommSurveyRecordActivity;
import soft.hb.activity.DischargeActivity;
import soft.hb.activity.ExhaustCheckActivity;
import soft.hb.activity.IndexActivity;
import soft.hb.activity.SurveyRecordActivity;
import zuo.biao.library.base.BaseFragment;

/**用户列表界面fragment
 * @author Lemon
 * @use new UserListFragment(),详细使用见.DemoFragmentActivity(initData方法内)
 * @must 查看 .HttpManager 中的@must和@warn
 *       查看 .SettingUtil 中的@must和@warn
 */
public class HomeFragment extends BaseFragment {

	public static HomeFragment createInstance() {
		HomeFragment fragment = new HomeFragment();
		return fragment;
	}

	//与Activity通信>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		setContentView(R.layout.index_activity);
		//功能归类分区方法，必须调用<<<<<<<<<<
		initView();
		initData();
		initEvent();
		//功能归类分区方法，必须调用>>>>>>>>>>

		return view;
	}


	@Override
	public void initView() {

	}

	@Override
	public void initData() {

	}

	@Override
	public void initEvent() {


		findView(R.id.card_survey_record).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {

				Acp.getInstance(getActivity()).request(new AcpOptions.Builder()
								.setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE
										, Manifest.permission.READ_PHONE_STATE
										, Manifest.permission.CAMERA)
								.build(),
						new AcpListener() {
							@Override
							public void onGranted() {
								//检查（勘验）
								startActivity(SurveyRecordActivity.createIntent(getActivity()));

							}
							@Override
							public void onDenied(List<String> permissions) {
								showShortToast("请打开权限！");
							}
						});
			}
		});
		findView(R.id.lay_exhaust_detection).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {

				Acp.getInstance(getActivity()).request(new AcpOptions.Builder()
								.setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE
										, Manifest.permission.READ_PHONE_STATE
										, Manifest.permission.CAMERA)
								.build(),
						new AcpListener() {
							@Override
							public void onGranted() {
								//检查（勘验）
								startActivity(DischargeActivity.createIntent(getActivity()));

							}
							@Override
							public void onDenied(List<String> permissions) {
								showShortToast("请打开权限！");
							}
						});
			}
		});
		findView(R.id.card_emission_exceeding_standard).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Acp.getInstance(getActivity()).request(new AcpOptions.Builder()
								.setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE
										, Manifest.permission.READ_PHONE_STATE
										, Manifest.permission.CAMERA)
								.build(),
						new AcpListener() {
							@Override
							public void onGranted() {
								//检查（勘验）
								startActivity(ExhaustCheckActivity.createIntent(getActivity()));

							}
							@Override
							public void onDenied(List<String> permissions) {
								showShortToast("请打开权限！");
							}
						});
			}
		});

		findView(R.id.card_survey_record1).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {

				Acp.getInstance(getActivity()).request(new AcpOptions.Builder()
								.setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE
										, Manifest.permission.READ_PHONE_STATE
										, Manifest.permission.CAMERA)
								.build(),
						new AcpListener() {
							@Override
							public void onGranted() {
								//检查（勘验）
								startActivity(CommSurveyRecordActivity.createIntent(getActivity()));

							}
							@Override
							public void onDenied(List<String> permissions) {
								showShortToast("请打开权限！");
							}
						});
			}
		});
	}
}